<template>
	<view class="page">
		<view class="summary-container">
			<image :src="photo" mode="widthFix" class="photo"></image>
			<view class="summary">
				<view class="row">
					<text class="name">{{ name }}</text>
					<image
						:src="realAuth==2 ? '../../static/mine/icon-1.png':'../../static/mine/icon-2.png'"
						mode="widthFix"
						class="auth-icon"
					></image>
					<text :class="realAuth==2 ? 'auth' : 'unauth'">{{ realAuth==1 ? '未认证' : (realAuth==2 ? '已认证' : '认证审核中') }}</text>
				</view>
				<view class="row">
					<view class="attribute">
						<view class="item">接驾：{{ years }}年</view>
						<view class="item">等级：Lv{{ level }}</view>
						<view class="item">接单：{{ changeNumber(totalOrder) }}</view>
					</view>
				</view>
			</view>
		</view>
		<view class="notice-container">
			<view class="notice-title">
				<image src="../../static/mine/icon-3.png" mode="widthFix"></image>
				<text>{{ levelName }}</text>
			</view>
			<view class="desc">升级Lv{{ level + 1 }}等级还需接单{{ 50 - (totalOrder % 50) }}个，并且为顾客提供安全和高质量驾驶服务</view>
		</view>
		<view class="nav-container">
			<view class="row">
				<view class="item" @tap="toPage('../../wallet/wallet/wallet')">
					<image src="../../static/mine/icon-4.png" mode="widthFix"></image>
					<view class="info">
						<text class="title">钱包</text>
						<text class="desc">总额{{ balance }}元</text>
					</view>
				</view>
				<view class="border-column"></view>
				<view class="item" @tap="toTab('pages/order_list/order_list')">
					<image src="../../static/mine/icon-5.png" mode="widthFix"></image>
					<view class="info">
						<text class="title">订单</text>
						<text class="desc">本周有{{ weekOrder }}单</text>
					</view>
				</view>
			</view>
			<view class="border-row"></view>
			<view class="row">
				<view class="item">
					<image src="../../static/mine/icon-6.png" mode="widthFix"></image>
					<view class="info">
						<text class="title">顾客评价</text>
						<text class="desc">近期{{ weekComment }}条好评</text>
					</view>
				</view>
				<view class="border-column"></view>
				<view class="item">
					<image src="../../static/mine/icon-7.png" mode="widthFix"></image>
					<view class="info">
						<text class="title">我的申诉</text>
						<text class="desc">正在申诉{{ appeal }}件</text>
					</view>
				</view>
			</view>
		</view>
		<view class="tab-container">
			<view class="item" @tap="this.toPage('../heat_chart/heat_chart')">
				<view class="ball ball-1"></view>
				<text>订单热点区域</text>
			</view>
			<view class="item" @tap="this.toPage('../../user/fine_list/fine_list')">
				<view class="ball ball-2"></view>
				<text>我的罚款</text>
			</view>
			<view class="item">
				<view class="ball ball-3"></view>
				<text>本月排名</text>
			</view>
			<view class="item">
				<view class="ball ball-4"></view>
				<text>我的数据</text>
			</view>
		</view>
		<u-cell-group :border="false">
			<u-cell-item
				icon="account-fill"
				:icon-style="icon"
				title="账号设置与安全"
				:border-top="false"
				@click="this.toPage('../../user/account/account')"
			/>
			<u-cell-item icon="server-fill" :icon-style="icon" title="联系客服" @click="serviceHandle" />
			<u-cell-item icon="trash-fill" :icon-style="icon" title="清理缓存" @click="clearHandle" />
			<u-cell-item
				icon="file-text-fill"
				:icon-style="icon"
				title="用户指南"
				:border-bottom="false"
				@click="this.toPage('../../rule/user_guide/user_guide')"
			/>
		</u-cell-group>
		<view class="exit"><button class="btn" @tap="logoutHandle()">退出系统</button></view>
		<u-top-tips ref="uTips"></u-top-tips>
	</view>
</template>

<script>
let dayjs = require('dayjs');
export default {
	data() {
		return {
			icon: {
				color: '#8A8B8F',
				'margin-top': '-1rpx'
			},
			name: '',
			photo: '',
			realAuth: 2,
			years: 0,
			level: 0,
			levelName: '',
			balance: 0,
			totalOrder: 0,
			weekOrder: 0,
			weekComment: 0,
			appeal: 0
		};
	},
	methods: {
		toTab(){
			uni.switchTab({
				url:'/pages/order_list/order_list'
			})
		},
		//清理缓存
		clearHandle() {
		    uni.vibrateShort({});
		    uni.showModal({
		        title: '提示消息',
		        content: '清理本地缓存',
		        success: function(resp) {
		            if (resp.confirm) {
		                uni.vibrateShort({});
		                uni.showLoading({
		                    title: '清理中...'
		                });
		                //删除Storage中不必要的缓存
		                let cache = uni.getStorageInfoSync();
		                for (let key of cache.keys) {
							//跳过Token和实名认证标识
		                    if (key == 'token' || key == 'realAuth') {
		                        continue;
		                    }
							//删除不必要的缓存
		                    uni.removeStorageSync(key); 
		                    console.log('删除Storage缓存成功:' + key);
		                }
		
		                //删除保存的临时文件
		                uni.getSavedFileList({
		                    success: function(resp) {
		                        for (let item of resp.fileList) {
		                            let path = item.filePath;
		                            uni.removeSavedFile({
		                                filePath: path,
		                                success: function() {
		                                    console.log('缓存文件删除成功');
		                                }
		                            });
		                        }
		                    }
		                });
		                setTimeout(function() {
							uni.hideLoading();
		                    uni.showToast({
		                        title: '清理完毕'
		                    });
		                }, 500);
		            }
		        }
		    });
		},
		//联系客服
		serviceHandle() {
		    uni.vibrateShort({});
		    uni.makePhoneCall({
		        phoneNumber: '10086'
		    });
		},
		logoutHandle(){
			let self = this;
			uni.vibrateShort({});
			uni.showModal({
				title: '提示信息',
				content: '确认退出系统？',
				success: function(resp) {
					if (resp.confirm) {
						self.ajax(self.url.logout, 'GET', null, function(resp) {
							uni.removeStorageSync('realAuth');
							uni.removeStorageSync('token');
							uni.showToast({
								title: '已经退出系统',
								success: function() {
									setTimeout(function() {
										uni.redirectTo({
											url: '../login/login'
										});
									}, 1500);
								}
							});
						});
					}
				}
			});
		}
	},
	onShow: function() {
		let self = this;
		this.ajax(this.url.searchDriverBaseInfo, 'POST', null, function(resp) {
			// console.log(resp.data);
			let result = resp.data.result;
			self.name = result.name;
			self.photo = result.photo;
			self.realAuth = result.realAuth;
			uni.setStorage({
				key: "realAuth",
				data: result.realAuth
			})
			let createTime = dayjs(result.createTime, 'YYYY-MM-DD');
			let current = dayjs();
			//计算日期差
			self.years = current.diff(createTime, 'years');
			self.level = result.summary.level;
			if (self.level < 10) {
				self.levelName = '初级司机';
			} else if (self.level < 30) {
				self.levelName = '中级司机';
			} else if (self.level < 50) {
				self.levelName = '高级司机';
			} else {
				self.levelName = '王牌司机';
			}
			self.balance = result.balance;
			self.totalOrder = result.summary.totalOrder;
			self.weekOrder = result.summary.weekOrder;
			self.weekComment = result.summary.weekComment;
			self.appeal = result.summary.appeal;
		});
	},
	onHide: function() {
		
	}
};
</script>

<style lang="less">
@import url('mine.less');
</style>
